﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TankDemo
{
    public partial class FormQuestion : Form
    {
        public FormQuestion()
        {
            InitializeComponent();
        }
        private string imgurl = "http://39.97.172.34:8080/";
        private void button7_Click(object sender, EventArgs e)
        {
            string xz = "";
            if (checkBox1.Checked)
            {
                xz = "A";
            }
            else if (checkBox2.Checked)
            {
                xz = "B";
            }
            else if (checkBox3.Checked)
            {
                xz = "C";
            }
            else if (checkBox4.Checked)
            {
                xz = "D";
            }
            else
            {
                xz = "";
                MessageBox.Show("请选择正确答案！");
            }
            if (xz != "")
            {
                DbHelperMySQL db = new DbHelperMySQL();
                int i = db.ExecuteSql("INSERT INTO questiontab(Type,Question,OptsA,OptsB,OptsC,OptsD,Answer,opt) VALUES ( 0, '" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox3.Text + "', '" + textBox4.Text + "', '" + textBox5.Text + "', '" + xz + "', 0);");
                if (i > 0)
                {
                    SelSqlQuestion(0, 0);
                    MessageBox.Show("添加成功");


                    checkBox1.Checked = false;
                    checkBox2.Checked = false;
                    checkBox3.Checked = false;
                    checkBox4.Checked = false;
                    textBox1.Text = "";
                    textBox2.Text = "";
                    textBox3.Text = "";
                    textBox4.Text = "";
                    textBox5.Text = "";
                }
            }

        }

        private void checkBox1_MouseDown(object sender, MouseEventArgs e)
        {
            bool b = (sender as CheckBox).Checked;

            checkBox1.Checked = false;
            checkBox2.Checked = false;
            checkBox3.Checked = false;
            checkBox4.Checked = false;

            (sender as CheckBox).Checked = b;
        }

        private void FormQuestion_Load(object sender, EventArgs e)
        {
            SelTkList();
        }
        private void SelSqlQuestion(int type, int opt)
        {



            if (opt == 0)
            {
                DbHelperMySQL db = new DbHelperMySQL();

                DataSet dataSet = db.Query("select id,question,optsA,optsB,optsC,optsD,Answer from Questiontab where opt=" + opt + " and type=" + type);

                //设置表格控件的DataSource属性
                dataGridView1.DataSource = dataSet.Tables[0];
                dataGridView1.Columns[0].HeaderText = "编号";
                dataGridView1.Columns[1].HeaderText = "问题";
                dataGridView1.Columns[2].HeaderText = "选项A";
                dataGridView1.Columns[3].HeaderText = "选项B";
                dataGridView1.Columns[4].HeaderText = "选项C";
                dataGridView1.Columns[5].HeaderText = "选项D";
                dataGridView1.Columns[6].HeaderText = "答案";
            }
            else if (opt == 1)
            {
                DbHelperMySQL db = new DbHelperMySQL();

                DataSet dataSet = db.Query("select id,question,Answer from Questiontab where opt=" + opt + " and type=" + type);

                //设置表格控件的DataSource属性
                dataGridView2.DataSource = dataSet.Tables[0];
                dataGridView2.Columns[0].HeaderText = "编号";
                dataGridView2.Columns[1].HeaderText = "问题";
                dataGridView2.Columns[2].HeaderText = "答案";
            }
            else if (opt == 2)
            {
                DbHelperMySQL db = new DbHelperMySQL();

                DataSet dataSet = db.Query("select id,optsA,optsB,Answer from Questiontab where opt=" + opt + " and type=" + type);

                //设置表格控件的DataSource属性
                dataGridView3.DataSource = dataSet.Tables[0];
                dataGridView3.Columns[0].HeaderText = "编号";
                dataGridView3.Columns[1].HeaderText = "选项A";
                dataGridView3.Columns[2].HeaderText = "选项B";
                dataGridView3.Columns[3].HeaderText = "答案";
            }



        }

        private void button1_Click(object sender, EventArgs e)
        {
            SelSqlQuestion(0, 0);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SelSqlQuestion(0, 1);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string xz = "";
            if (checkBox5.Checked)
            {
                xz = "0";
            }
            else if (checkBox8.Checked)
            {
                xz = "1";
            }
            else
            {
                xz = "";
                MessageBox.Show("请选择正确答案！");
            }
            if (xz != "")
            {
                DbHelperMySQL db = new DbHelperMySQL();
                int i = db.ExecuteSql("INSERT INTO questiontab(Type,Question,Answer,opt) VALUES ( 0, '" + textBox10.Text + "', '" + xz + "', 1);");
                if (i > 0)
                {
                    SelSqlQuestion(0, 1);
                    MessageBox.Show("添加成功");


                    checkBox5.Checked = false;
                    checkBox8.Checked = false;
                    textBox10.Text = "";
                }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {
            DbHelperMySQL db = new DbHelperMySQL();
            int i = db.ExecuteSql("INSERT INTO questionsettab(selSum,selMark,judSum,judMark) VALUES (  " + textBox6.Text + "," + textBox7.Text + "," + textBox9.Text + "," + textBox8.Text + ");");
            if (i > 0)
            {
                MessageBox.Show("添加成功");
            }
        }

        private int selquestId = 0;
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

            selquestId = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());

            textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
            textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            textBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
            textBox4.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
            textBox5.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();


        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (selquestId != 0)
            {
                string xz = "";
                if (checkBox1.Checked)
                {
                    xz = "A";
                }
                else if (checkBox2.Checked)
                {
                    xz = "B";
                }
                else if (checkBox3.Checked)
                {
                    xz = "C";
                }
                else if (checkBox4.Checked)
                {
                    xz = "D";
                }
                else
                {
                    xz = "";
                    MessageBox.Show("请选择正确答案！");
                }
                if (xz != "")
                {
                    DbHelperMySQL db = new DbHelperMySQL();

                    int i = db.ExecuteSql("update  questiontab set question='" + textBox1.Text + "',optsA='" + textBox2.Text + "',optsB='" + textBox3.Text + "',optsC='" + textBox4.Text + "',optsD='" + textBox5.Text + "',Answer='" + xz + "' where id=" + selquestId);
                    if (i > 0)
                    {
                        MessageBox.Show("修改成功");
                    }
                }
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (selquestId != 0)
            {
                DbHelperMySQL db = new DbHelperMySQL();
                int i = db.ExecuteSql("delete from questiontab where id=+" + selquestId);
                if (i > 0)
                {
                    MessageBox.Show("删除成功");
                }
            }
        }
        private List<Tanke> tankes = new List<Tanke>();




        private Dictionary<string, Object> TankeTitleToIdDict = new Dictionary<string, Object>();
        /// <summary>
        /// 显示坦克类型 下拉列表
        /// </summary>
        private void SelTkList()
        {
            TankeTitleToIdDict.Clear();
            Tanke_listView.Items.Clear();
            comboBox1.Items.Clear();
            T1_TanKeComboBox.Items.Clear();
            DbHelperMySQL db = new DbHelperMySQL();

            MySql.Data.MySqlClient.MySqlDataReader dt = db.ExecuteReader("select * from tanketab");
            while (dt.Read())
            {

                Tanke tanke = new Tanke();
                tanke.id = int.Parse(dt.GetString("id"));
                tanke.title = dt.GetString("title");

                ListViewItem viewItem = new ListViewItem();
                viewItem.Text = tanke.title;
                viewItem.Tag = tanke;
                Tanke_listView.Items.Add(viewItem);

                TankeTitleToIdDict.Add(viewItem.Text, tanke);
                //坦克图的
                comboBox1.Items.Add(viewItem.Text);
                //坦克阅读的
                T1_TanKeComboBox.Items.Add(viewItem.Text);

            }

        }

        private ListViewItem listViewItem1 = null;
        private ListViewItem listViewItem2 = null;
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Tanke_listView.SelectedItems.Count > 0)
            {
                listViewItem1 = Tanke_listView.SelectedItems[0];
                textBox12.Text = listViewItem1.Text;

            }
        }

        private void listView2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView2.SelectedItems.Count > 0)
            {
                listViewItem2 = listView2.SelectedItems[0];
                textBox15.Text = listViewItem2.Text;

                Tanketu ttu = listViewItem2.Tag as Tanketu;
                pictureBox1.ImageLocation = imgurl + ttu.img;

            }
        }
        /// <summary>
        /// 添加坦克类型
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button15_Click(object sender, EventArgs e)
        {


            if (listViewItem1.Tag != null)
            {

                DbHelperMySQL db = new DbHelperMySQL();
                int i = db.ExecuteSql("INSERT INTO tanketab(title) VALUES ( '" + textBox12.Text + "');");
                if (i > 0)
                {
                    textBox12.Text = "";

                    MessageBox.Show("添加成功");

                    //刷新
                    SelTkList();
                }
            }
        }
        /// <summary>
        /// 修改坦克类型
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button11_Click(object sender, EventArgs e)
        {
            if (listViewItem1.Tag != null)
            {
                DbHelperMySQL db = new DbHelperMySQL();
                int i = db.ExecuteSql("update  tanketab set title='" + textBox12.Text + "' where id=" + listViewItem1.Tag.ToString());
                if (i > 0)
                {
                    MessageBox.Show("修改成功");
                    //刷新
                    SelTkList();
                }
            }

        }
        /// <summary>
        /// 删除坦克类型
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button16_Click(object sender, EventArgs e)
        {
            if (listViewItem1.Tag != null)
            {
                DbHelperMySQL db = new DbHelperMySQL();
                int i = db.ExecuteSql("delete from  tanketab  where id=" + listViewItem1.Tag.ToString());
                if (i > 0)
                {
                    MessageBox.Show("删除成功");
                    //刷新
                    SelTkList();
                }
            }
        }
        /// <summary>
        /// 打开图片选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button13_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = openFileDialog1.ShowDialog();
            if (dialogResult == DialogResult.OK)
            {
                pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button10_Click(object sender, EventArgs e)
        {

            if (textBox15.Text == "")
            {
                MessageBox.Show("请添加图示文字说明！");
            }
            else
            {


                try
                {





                    object obj = null;

                    TankeTitleToIdDict.TryGetValue(comboBox1.Text, out obj);

                    if (obj != null)
                    {
                        Tanke tk = obj as Tanke;

                        string sql = "insert into   tanketu(title,tankeid) values('" + textBox15.Text + "'," + tk.id + ")";
                        if (openFileDialog1.FileName != "openFileDialog1")
                        {
                            Dictionary<string, Object> dict = PublicClass.updateImg(openFileDialog1.FileName);
                            sql = "insert into   tanketu(title,img,tankeid) values('" + textBox15.Text + "','" + dict["filename"].ToString() + "'," + tk.id + ")";

                        }

                        DbHelperMySQL db = new DbHelperMySQL();




                        int i = db.ExecuteSql(sql);
                        if (i > 0)
                        {
                            MessageBox.Show("添加成功");
                            //刷新
                            shuaxinListView2();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("上传修改失败");
                }

            }

        }

        private void button14_Click(object sender, EventArgs e)
        {

        }

        private void button17_Click(object sender, EventArgs e)
        {
            string xz = "";
            if (checkBox7.Checked)
            {
                xz = "A";
            }
            else if (checkBox6.Checked)
            {
                xz = "B";
            }
            else
            {
                xz = "";
                MessageBox.Show("请选择正确答案！");
            }
            if (xz != "")
            {
                DbHelperMySQL db = new DbHelperMySQL();
                int i = db.ExecuteSql("INSERT INTO questiontab(Type,Question,optsA,optsB,Answer,opt) VALUES ( 0,'', '" + textBox13.Text + "', '" + textBox14.Text + "', '" + xz + "', 2);");
                if (i > 0)
                {
                    SelSqlQuestion(0, 2);
                    MessageBox.Show("添加成功");


                    checkBox7.Checked = false;
                    checkBox6.Checked = false;
                    textBox13.Text = "";
                    textBox14.Text = "";
                }
            }
        }

        private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
        {
            switch (e.TabPageIndex)
            {
                case 0:
                //坦克列表
                case 1:
                //坦克图示
                case 6:
                    //坦克阅读
                    SelTkList();
                    break;
                case 2:
                    //问答题设置
                    SelSqlQuestion(0, 2);
                    break;
                case 3:
                    //卷面设置
                    DbHelperMySQL db = new DbHelperMySQL();
                    MySql.Data.MySqlClient.MySqlDataReader dt = db.ExecuteReader("select selSum,selMark,judSum,judMark from questionsettab");
                    if (dt.Read())
                    {
                        textBox6.Text = dt.GetString("selSum").ToString();
                        textBox7.Text = dt.GetString("selMark").ToString();
                        textBox9.Text = dt.GetString("judSum").ToString();
                        textBox8.Text = dt.GetString("judMark").ToString();
                    }

                    dt.Close();
                    dt.Dispose();
                    break;
                case 4:
                    //选择题
                    SelSqlQuestion(0, 0);
                    break;
                case 5:
                    //判断题
                    SelSqlQuestion(0, 1);
                    break;

            }
        }

        private void textBox15_TextChanged(object sender, EventArgs e)
        {

        }

        private void label16_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 选择坦克下拉列表【图示中】
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

            shuaxinListView2();
        }


        private void shuaxinListView2() {
            if (comboBox1.Text != "选择坦克类型")
            {
                listView2.Items.Clear();
                object obj = null;

                TankeTitleToIdDict.TryGetValue(comboBox1.Text, out obj);

                if (obj != null)
                {
                    Tanke tk = obj as Tanke;

                    //查询列表
                    DbHelperMySQL db = new DbHelperMySQL();


                    MySql.Data.MySqlClient.MySqlDataReader dt = db.ExecuteReader("select * from tanketu where tankeid=" + tk.id);
                    while (dt.Read())
                    {
                        Tanketu t = new Tanketu();
                        t.title = dt.GetString("title");
                        t.tankeid = int.Parse(dt.GetString("tankeid"));
                        t.img = dt.GetString("img");
                        t.id = int.Parse(dt.GetString("id"));


                        ListViewItem listViewItem = new ListViewItem();
                        listViewItem.Tag = t;
                        listViewItem.Text = dt.GetString("title");
                        listView2.Items.Add(listViewItem);
                    }



                    dt.Close();
                    dt.Dispose();
                }
            }
        }



        private List<Theme> themes = new List<Theme>();

        private ListViewItem T1_listViewItem1 = null;
        private ListViewItem T1_listViewItem2 = null;

        private Dictionary<string, Tanke> T1_TankeDict = new Dictionary<string, Tanke>();


        private void SelTopic(){

            T1_ListView.Items.Clear();
           Theme theme = T1_TopListView.SelectedItems[0].Tag as Theme;

            DbHelperMySQL db = new DbHelperMySQL();

            MySql.Data.MySqlClient.MySqlDataReader dt= db.ExecuteReader("select * from topic where theme_id="+ theme.id);
            while (dt.Read())
            {
                Topic topic = new Topic();
                topic.theme_id = int.Parse(dt.GetString("theme_id"));
                topic.title = dt.GetString("title");
                topic.id = int.Parse((dt.GetString("id")));
                topic.title_id = int.Parse(dt.GetString("title_id"));
                topic.topic_img = dt.GetString("topic_img");


                ListViewItem listViewItem = new ListViewItem();
                listViewItem.Tag = topic;
                listViewItem.Text = topic.title;
                T1_ListView.Items.Add(listViewItem);
            }


            dt.Close();
            dt.Dispose();


        }

        private void SelThemes(int n = 0)
        {

            
            Tanke tk= TankeTitleToIdDict[T1_TanKeComboBox.Text] as Tanke;
            T1_LoadPictureBox.Image = null;
            T1_TopListView.Items.Clear();
            T1_ListView.Items.Clear();



            DbHelperMySQL db = new DbHelperMySQL();

            MySql.Data.MySqlClient.MySqlDataReader dt = db.ExecuteReader("select * from theme where type=0 and tankeid=" + tk.id);
            while (dt.Read())
            {
                Theme t = new Theme();
                t.id = int.Parse((dt.GetString("id")));
                t.title = dt.GetString("title");
                ListViewItem listViewItem = new ListViewItem();
                listViewItem.Tag = t;
                listViewItem.Text = t.title;
                T1_TopListView.Items.Add(listViewItem);

            }

            dt.Close();
            dt.Dispose();







            //T1_ShowListViewItem();

        }

        /// <summary>
        /// 选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void T1_TopAddButton_Click(object sender, EventArgs e)
        {
            if (T1_TanKeComboBox.Text == "请选择坦克类型")
            {
                MessageBox.Show("请选择坦克类型");
            }
            else
            {

                if (T1_TopTextBox.Text != "")
                {
                                            
                    Tanke tk    = TankeTitleToIdDict[T1_TanKeComboBox.Text] as Tanke;

                    int tankeid = tk.id;


                    DbHelperMySQL db = new DbHelperMySQL();
                    int i = db.ExecuteSql("INSERT INTO theme(title,title_id,tankeid,type,bookimg) VALUES ( '" + T1_TopTextBox.Text + "', 0," + tankeid + ",0,'');");
                    if (i > 0)
                    {
                        T1_TopTextBox.Text = "";

                        MessageBox.Show("添加成功");

                        //刷新
                        SelThemes(1);
                    }
                }
            }
        }

        /// <summary>
        /// 选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void T1_TopListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (T1_TopListView.SelectedItems.Count > 0)
            {
                T1_listViewItem1 = T1_TopListView.SelectedItems[0];
                T1_TopTextBox.Text = T1_listViewItem1.Text;


                SelTopic();

            }
        }

        /// <summary>
        /// 选择坦克类型
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void T1_TanKeComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            SelThemes();
        }

        /// <summary>
        /// 按钮 修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void T1_TopUpdateButton_Click(object sender, EventArgs e)
        {
            if (T1_listViewItem1 != null)
            {
                Theme theme = T1_listViewItem1.Tag as Theme;
                DbHelperMySQL db = new DbHelperMySQL();
                int i = db.ExecuteSql("update  theme set title='" + T1_TopTextBox.Text + "' where id=" + theme.id);
                if (i > 0)
                {
                    MessageBox.Show("修改成功");
                    //刷新
                    SelThemes();
                }
            }
        }

        private void T1_TopDeleteButton_Click(object sender, EventArgs e)
        {
            if (T1_listViewItem1 != null)
            {
                Theme theme = T1_listViewItem1.Tag as Theme;
                DbHelperMySQL db = new DbHelperMySQL();
                int i = db.ExecuteSql("delete from  theme  where id=" + theme.id);
                if (i > 0)
                {
                    MessageBox.Show("删除成功");
                    //刷新
                    SelThemes();
                }
            }
        }

        private void T1_TopAddBookButton_Click(object sender, EventArgs e)
        {


            if (T1_listViewItem1 != null)
            {




                try
                {

                    DialogResult dialogResult = openFileDialog1.ShowDialog();
                    if (dialogResult == DialogResult.OK)
                    {
                        Dictionary<string, Object> dict = PublicClass.updateImg(openFileDialog1.FileName);
                        Theme theme = T1_listViewItem1.Tag as Theme;
                        DbHelperMySQL db = new DbHelperMySQL();
                        int i = db.ExecuteSql("update  theme set bookimg='" + dict["filename"] + "' where id=" + theme.id);
                        if (i > 0)
                        {
                            MessageBox.Show("修改成功");
                            //刷新
                            SelThemes();
                        }
                    }



                }
                catch (Exception ex)
                {
                    MessageBox.Show("上传修改失败");
                }

            }
        }

        private void T1_ListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (T1_ListView.SelectedItems.Count > 0)
            {
                T1_listViewItem2 = T1_ListView.SelectedItems[0];
                T1_TextBox.Text = T1_listViewItem2.Text;

                Topic topic = T1_listViewItem2.Tag as Topic;



                if (topic.topic_img != "")
                {
                    T1_LoadPictureBox.ImageLocation = imgurl + topic.topic_img;
                }
                else
                {
                    T1_LoadPictureBox.ImageLocation = "";
                }
            }
        }

        private void T1_AddButton_Click(object sender, EventArgs e)
        {
            if (T1_TextBox.Text != "" && T1_listViewItem1 != null)
            {

                Theme theme = T1_listViewItem1.Tag as Theme;



                DbHelperMySQL db = new DbHelperMySQL();
                int i = db.ExecuteSql("INSERT INTO topic(title,title_id,theme_id,topic_img) VALUES ( '" + T1_TextBox.Text + "', 0," + theme.id + ",'');");
                if (i > 0)
                {
                    T1_TextBox.Text = "";
                    MessageBox.Show("添加成功");
                    //刷新
                    SelTopic();
                }
            }
            else
            {
                MessageBox.Show("请选择上一级内容");
            }
        }

        private void T1_UpdateButton_Click(object sender, EventArgs e)
        {
            if (T1_listViewItem2 != null)
            {

                Topic topic = T1_listViewItem2.Tag as Topic;

                DbHelperMySQL db = new DbHelperMySQL();
                int i = db.ExecuteSql("update  topic set title='" + T1_TextBox.Text + "' where id=" + topic.id);
                if (i > 0)
                {
                    MessageBox.Show("修改成功");
                    //刷新
                    SelTopic();
                }
            }
        }

        private void T1_DeleteButton_Click(object sender, EventArgs e)
        {
            if (T1_listViewItem2 != null)
            {

                Topic topic = T1_listViewItem2.Tag as Topic;

                DbHelperMySQL db = new DbHelperMySQL();
                int i = db.ExecuteSql("delete form topic where id=" + topic.id);
                if (i > 0)
                {
                    MessageBox.Show("删除成功");
                    //刷新
                    SelTopic();
                }
            }
        }
        /// <summary>
        /// 打开文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void T1_OpenFileButton_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = openFileDialog1.ShowDialog();
            if (dialogResult == DialogResult.OK)
            {
                T1_LoadPictureBox.Image = Image.FromFile(openFileDialog1.FileName);
            }
        }
        /// <summary>
        /// 上传并修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void T1_UpButton_Click(object sender, EventArgs e)
        {
            if (T1_listViewItem1 == null || T1_listViewItem2 == null)
            {
                MessageBox.Show("请选择对应上一级！");
            }


            try
            {


                Dictionary<string, Object> dict = PublicClass.updateImg(openFileDialog1.FileName);

               
                Topic topic = T1_listViewItem2.Tag as Topic;

                DbHelperMySQL db = new DbHelperMySQL();
                int i = db.ExecuteSql("update  topic set topic_img='" + dict["filename"].ToString() + "' where id=" + topic.id);
                if (i > 0)
                {
                    MessageBox.Show("添加成功");
                    //刷新
                    //SelThemes();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("上传修改失败");
            }

        }
    }
}
